<%@ page language="java" import="java.util.*,java.text.*,java.sql.*"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<form name="form1" method="post" action="">
		<tr>
			<td>课程名:</td>
			<td><input type="text" name="a"
			</td>
			<br />
		<tr />
		<tr>
			<td>学时:</td>
			<td><input type="text" name="b"
			</td>
			<br />
		<tr />
		<tr>
			<td>年级ID:</td>
			<td><input type="text" name="c"
			</td>
			<br />
		<tr />
		<input type="submit" name="submit" value="提交"> <input
			type="submit" name="submit" value="取消">
	</form>

	<%
		if (request.getParameter("a") != null&&request.getParameter("b") != null&&request.getParameter("c") != null) {
			Connection con = null;
			PreparedStatement pre = null;
			try {
				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			try {
				con = DriverManager
						.getConnection(
								"jdbc:mysql://localhost:3306/soarroad?useSSL=false",
								"root", "19890909w");
				out.println("连接成功！ ");
				String sql = "insert into `subject`(subjectname,classhour,gradeid)values(?,?,?)";
				pre = con.prepareStatement(sql);
				pre.setString(1, request.getParameter("a"));
				pre.setString(2, request.getParameter("b"));
				pre.setString(3, request.getParameter("c"));
				int o = pre.executeUpdate();
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				if (null != pre) {
					try {
						pre.close();
						out.print("关闭连接!");
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (null != con) {
					try {
						con.close();
						out.print("关闭连接!");
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
			}
		} else
			return;
	%>
</body>
</html>